package com.heavenick.app.service;

import java.io.InputStream;
import java.util.List;

import javax.sql.DataSource;

import org.apache.ibatis.mapping.Environment;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import com.heavenick.app.dao.SimpleDao;
import com.heavenick.app.model.pojo.pr_city;
import com.heavenick.core.dao.DaoFactory;
import com.heavenick.core.dao.impl.DaoFactoryImpl;

public class Pr_cityTest {
	private static DaoFactory dao = new DaoFactoryImpl(); 
	
	public static void main(String[] args) throws BeansException, Exception {
//		SqlSessionFactoryBuilder ssfb = new SqlSessionFactoryBuilder();
//		InputStream inputStream = Pr_cityTest.class.getResourceAsStream("/META-INF/mybatis/mybatis-config.xml");
//		
//		SqlSessionFactory ssf = ssfb.build(inputStream);
//		
//		
//		Configuration config = new Configuration();
//		DataSource dataSource = null;
//		DriverManagerDataSource  dmds = new DriverManagerDataSource();
//		dmds.
//		
////		Environment environment = new Environment();
//		
//		
////		config.setEnvironment(environment);
//		
//		ssfb.build(config);
		
		
		ApplicationContext ac = new ClassPathXmlApplicationContext("/META-INF/spring/*");
		SqlSessionFactory ssf = ac.getBean(SqlSessionFactory.class);
		
		
		
		SqlSession sqlSession = ssf.openSession();
		dao.setSqlSession(sqlSession);
		SimpleDao simpledao = dao.getDao(SimpleDao.class);
		List<pr_city> pclist = simpledao.selectWithPage(new pr_city());
		for (pr_city pr_city : pclist) {
			System.out.println(pr_city);
		}
		
		simpledao = dao.getDao(SimpleDao.class);
		pr_city pc = simpledao.selectByPrimaryKey(571L);
		System.out.println(pc);
	}
}
